﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace WebApplication5
{
    public class SqlHerper
    {
        private static string constr = "server=.;uid=Windows;database=Student_db";

        private SqlConnection  con = null;
        public SqlHerper() {

            con = new SqlConnection(constr );
        }
        public DataTable Get(string sql ,SqlParameter [] pars) {

            try
            {
                if (con.State ==ConnectionState.Closed )
                {
                    con.Open();
                }
                SqlCommand cmd = new SqlCommand(sql,con );
                if (cmd !=null &&pars.Length !=0)
                {
                    cmd.Parameters.AddRange(pars );
                };
                return cmd.ExecuteNonQuery() > 0;

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
             
                if (con != null)
                {
                    con.Close();
                }
            }
        }

        internal static DataTable Get(object sql, SqlParameter[] pars)
        {
            throw new NotImplementedException();
        }
    }
}